package com.firegod.student.controller;

import com.firegod.commonutils.vo.ResultVo;
import com.firegod.student.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/info/{userId}")
    @ApiOperation("获取用户信息")
    public ResultVo getUserInfo(@PathVariable String userId) {
        try {
            return ResultVo.ok().data(userService.getUserInfo(userId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.error().message(e.getMessage());
        }
    }

    @GetMapping("/logout")
    @ApiOperation("学生登出")
    public ResultVo logout() {
        userService.logout();
        return ResultVo.ok();
    }
}
